<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="安装单" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillEdit.css" />
<script src="/js/popup_ext.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function doSave(){
		document.getElementById("buttonDiv").style.display="none";
		document.getElementById("waitDiv").style.display="";
		<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';SETU_EXAM;')!=-1}">
			ShowConfirm('确认框','是否同时审核？',340,80,"doSaveCallBack()");
		</c:if>
		<c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';SETU_EXAM;')==-1}">
			frm.submit();
		</c:if>
	}
	function doSaveCallBack(){
		if(popRetVal!=null){
			document.getElementById("examine").value="1";
		}
		frm.submit();
	}
	function doCancel(){
		if(window.opener){
			window.close();
		}else{
			parent.ClosePop();
		}
	}
	function doPrint(id){
		showWin(900,600,"/business/SetuBillPrint.ihtm?id="+id);
	}
	function changeTimeSelect(obj,targetName){
		document.getElementById(targetName).value=obj.value;
	}
	function selectStafferRate(type,idObjId,nameObjId){
		var url="/base/StafferMainForSelect.ihtm?type=MULTI";
		ShowIframe("选择员工",url,800,500,"selectStafferRateCallBack('"+type+"','"+idObjId+"','"+nameObjId+"')",1024,600);	
	}
	function selectStafferRateCallBack(type,idObjId,nameObjId){
		if(popRetVal!=null){
			var idStr="";
			var nameStr="";
			for(i=0;i<popRetVal.length;i++){
				if(idStr!=""){
					idStr=idStr+";";
					nameStr=nameStr+";";
				}
				idStr=idStr+popRetVal[i][0];
				nameStr=nameStr+popRetVal[i][2];
			}
			if(idStr!=""){
				var url="/business/SetStafferRate.ihtm?type="+type+"&id_str="+idStr+"&name_str="+encodeURIComponent(nameStr);
				ShowIframe("设置占比",url,335,250,"selectStafferRateCallBackExt('"+idObjId+"','"+nameObjId+"')");
			}
		}
	}
	function selectStafferRateCallBackExt(idObjId,nameObjId){
		if(popRetVal!=null){
			//var idStr=document.getElementById(idObjId).value;
			//var nameStr=document.getElementById(nameObjId).value;
			var idStr="";
			var nameStr="";
			if(idStr==""){
				idStr=";"+popRetVal[0]+";";
				nameStr=popRetVal[1];
			}else{
				idStr=idStr+popRetVal[0]+";";
				nameStr=nameStr+";"+popRetVal[1];
			}
			document.getElementById(idObjId).value=idStr;
			document.getElementById(nameObjId).value=nameStr;
		}
	}
	function clearStafferRate(idObjId,nameObjId){
		document.getElementById(idObjId).value="";
		document.getElementById(nameObjId).value="";
	}
	function selectStaffer(idObjId,nameObjId){
		var url="/base/StafferMainForSelect.ihtm";
		ShowIframe("选择员工",url,800,500,"selectStafferCallBack('"+idObjId+"','"+nameObjId+"')",1024,600);
	}
	function selectStafferCallBack(idObjId,nameObjId){
		if(popRetVal!=null){
			var arr=popRetVal.split(";");
			document.getElementById(idObjId).value=arr[0];
			document.getElementById(nameObjId).value=arr[1];
		}
	}
	function doInit(){
		var itemNum=document.getElementById("item_num").value-0;
		if(itemNum>0){
			document.getElementById("amount_0").select();
		}else{
			document.getElementById("cancelButton").focus();
		}
		showFormErrorMsg();
		resizePopwin();
	}
	function checkCbChange(obj,targObjId){
		if(obj.checked){
			document.getElementById(targObjId).value="Y";
		}else{
			document.getElementById(targObjId).value="N";
		}
	}
</script>
</head>
<body onload="doInit();">
<div class="Wrap">
	<form name="frm" method="post" enctype="multipart/form-data">
	<div class="Container">
		<div class="Contnet Paper">
			<c:set var="pageTopTitle" value="安装单" />
			<c:set var="codeReadOnlyStr" value="" /><!-- 编码框是否可点击 -->
			<c:set var="codeReadOnlyClassStr" value="" /><!-- 编码框颜色 -->
			<c:if test="${command.codeRule.generateRule!='MANUAL'}">
				<c:set var="codeReadOnlyStr" value="readonly='readonly'" />
				<c:set var="codeReadOnlyClassStr" value="disabled" />
			</c:if>
			
			<c:set var="dateEdit" value="Y" /><!-- 是否可以编辑日期 -->
			<c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';NO_BILL_DATE;')!=-1}">
				<c:set var="dateEdit" value="N" />
			</c:if>
			
			<c:if test="${command.setuBill.enabled=='N' || currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';SETU_BILL;')==-1 || id!=null && id!='' && command.setuBill.exam=='Y'}">
				<c:set var="disabledStr" value="disabled='disabled'" />
			</c:if>

			<!-- 提示信息 -->
			<%@ include file="../inc/BillPageTop.jsp"%>

			<!--单标题-->
			<br>
	        <table class="BillHeading" cellspacing="0" cellpadding="0">
	        	<tr>
		            <td width="301px;" rowspan="2" ><div class="CorpLogo"><img src="${enterpriseInfo.loginImage}" /></div></td>
		            <td width="301px;" rowspan="2" ><h1>${pageTopTitle}</h1></td>
		            <td width="301px;" class="tr vb codeTd">
		                <span class="MustInput">*</span>编号：
		                <spring:bind path="command.setuBill.billCode">
				    	<input type="text" class="tbBillCode TextBox ${codeReadOnlyClassStr}" ${codeReadOnlyStr} maxlength="30" onKeyUp="goNextInput('deliverDateStr');" id="${status.expression}" name="${status.expression}" value="${status.value}">
				    	<script language="javascript">
							setFormErrorMsg('<c:out value="${status.errorMessage}" />',1,'setuBill.billCode');
						</script>
			     		</spring:bind>
		            </td>
	        	</tr>
	        	<tr>
	            	<td class="tr">
		            	<span class="MustInput">*</span>派单日期：
		            	<spring:bind path="command.billDateStr">
		                    <input type="text" class="tbBillDate TextBox <c:if test="${dateEdit=='N'}">readonly</c:if>" maxlength="15" onKeyUp="goNextInput('setuBill.lm');" id="${status.expression}" name="${status.expression}" value="${status.value}" <c:if test="${dateEdit=='N'}">readonly="readonly"</c:if> />
		                    <c:if test="${dateEdit=='Y'}"><img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('billDateStr'),'yyyy-mm-dd',document.getElementById('billDateStr'));"></c:if>
		                    <select id="billDateHourSelect" class="ddlDateHour" onChange="changeTimeSelect(this,'billDateHour');" <c:if test="${dateEdit=='N'}">disabled="disabled" style="background:#f6f6f6;"</c:if>>
		                        <c:forEach var="item" begin="0" step="1" end="23" varStatus="i"><c:if test="${i.index<10}"><c:set var="item" value="0${item}" /></c:if><option value="${item}" <c:if test="${item==command.billDateHour}">selected</c:if>>${item}</option></c:forEach>
		                    </select>
		                    <select id="billDateMinuteSelect" class="ddlDateMinute" onChange="changeTimeSelect(this,'billDateMinute');" <c:if test="${dateEdit=='N'}">disabled="disabled" style="background:#f6f6f6;"</c:if>>
		                        <c:forEach var="item" begin="0" step="1" end="59" varStatus="i"><c:if test="${i.index<10}"><c:set var="item" value="0${item}" /></c:if><option value="${item}" <c:if test="${item==command.billDateMinute}">selected</c:if>>${item}</option></c:forEach>
		                    </select>
		                    <script language="javascript">
						    	setFormErrorMsg('<c:out value="${status.errorMessage}" />',2,'billDateStr');
						    </script>
		                </spring:bind>
	            	</td>
	        	</tr>
	        </table>

			<!-- 单头信息 -->
	        <div class="TopBottom_Border">
	        	<table class="BillHeadInfo" cellspacing="0" cellpadding="0">
	        		<tr>
	            		<td width="314px;">
	                		订货单位：${command.clientName}
	            		</td>
	            		<td width="386px;">
	                		联系人：
	                		<spring:bind path="command.setuBill.lm">
	                    	<input type="text" class="tbHead2_1 TextBox" maxlength="15" onKeyUp="goNextInput('setuBill.phon');" id="${status.expression}" name="${status.expression}" value="${status.value}" />
	                		<script language="javascript">
								setFormErrorMsg('<c:out value="${status.errorMessage}" />',4,'setuBill.lm');
							</script>
	                		</spring:bind>
	                		电话：
	                		<spring:bind path="command.setuBill.phon">
	                    	<input type="text" class="tbHead2_2 TextBox" maxlength="40" onKeyUp="goNextInput('setuBill.addr');" id="${status.expression}" name="${status.expression}" value="${status.value}" />
	                    	<script language="javascript">
						    	setFormErrorMsg('<c:out value="${status.errorMessage}" />',5,'setuBill.phon');
						    </script>
	                		</spring:bind>
	            		</td>
	            		<td width="204px;" class="tr">
	                		业务单号：${command.bbCode}
	            		</td>
	        		</tr>
	        	</table>
	        </div>

			<!-- 明细 -->
	        <input type="hidden" id="item_num" name="item_num" value="${fn:length(command.items)}">
	        <table id="BillDetails" class="BillDetails" width="100%" cellspacing="0" cellpadding="0">
	        	<tbody id="itemRowTbl">
	        	<tr>
					<th width="10%">项目类型</th>
					<th width="12%">内容</th>
					<th width="12%">材质</th>
					<th width="12%">规格</th>
					<th width="18%">制作要求</th>
					<th width="10%">订货数量</th>
					<th width="10%">本次安装</th>
					<th width="16%">备注</th>
				</tr>
				<c:forEach var="item" items="${command.items}" varStatus="i">
				<tr id="itemTr${i.index}">
					<td>
						<input class="TextBox readonly" readonly="readonly" type="text" style="width:60px" id="mt_name_${i.index}" name="mt_name_${i.index}" value="${item.makeTypeName}">
						<input type="hidden" id="id_${i.index}" name="id_${i.index}" value="${item.oldId}">
						<input type="hidden" id="bb_item_id_${i.index}" name="bb_item_id_${i.index}" value="${item.setuBillItem.bbItemId}">
					</td>
					<td>
						<input type="text" class="TextBox readonly" readonly="readonly" style="width:80px" id="cont_${i.index}" name="cont_${i.index}" value="<c:out value="${item.finishedContent}" />">
					</td>
					<td>
						<input type="text" class="TextBox readonly" readonly="readonly" style="width:80px" id="pro_name_${i.index}" name="pro_name_${i.index}" value="${item.productName}">
					</td>
					<td>
						<input type="text" class="TextBox readonly" readonly="readonly" style="width:80px" id="spe_${i.index}" name="spe_${i.index}" value="<c:out value="${item.specification}" />">
					</td>
					<td>
						<input type="text" class="TextBox readonly" readonly="readonly" style="width:140px" id="req_${i.index}" name="req_${i.index}" value="<c:out value="${item.makeRequire}" />">
					</td>
					<td>
						<input type="text" class="TextBox readonly" readonly="readonly" style="width:60px" id="amount_total_${i.index}" name="amount_total_${i.index}" value='<commonTag:parseBigDecimal source="${item.amountTotal}" />'>
					</td>
					<td>
						<input type="text" class="TextBox" style="width:60px" maxlength="10" id="amount_${i.index}" name="amount_${i.index}" value="${item.amountStr}">
					</td>
					<td>
						<input type="text" class="TextBox" style="width:120px" maxlength="200" id="mark_${i.index}" name="mark_${i.index}" value="${item.setuBillItem.mark}">
					</td>
				</tr>
				</c:forEach>
				</tbody>
			</table>
			
			<spring:bind path="command.items">
	        	<script language="javascript">
	          		setFormErrorMsg('<c:out value="${status.errorMessage}" />',6);
	        	</script>
			</spring:bind>
			
			<br>
			<!-- 单附加信息 -->
	        <div class="TopBottom_Border">
	        	<table class="BillElseInfo" cellspacing="0" cellpadding="0">
	        		<tr>
	            		<th width="84px">安装人员：</th>
	            		<td width="200px">
	            			<spring:bind path="command.setuBill.setuNameStr">
            				<input type="text" class="tbInfo1 TextBox readonly" readOnly="true" id="${status.expression}" name="${status.expression}" value="${status.value}" onmouseover="this.title=this.value" />
            				<img src="/images/make-a.gif" class="imgIconButton" onClick="selectStafferRate('SETUP','setuBill.setuIdStr','setuBill.setuNameStr');" title="选择安装员，用于计算该员工的安装产值" />
            				<img src="/images/icon_del.gif" class="imgIconButton" onClick="clearStafferRate('setuBill.setuIdStr','setuBill.setuNameStr');">
        					<script language="javascript">
								setFormErrorMsg('<c:out value="${status.errorMessage}" />',7);
							</script>
        					</spring:bind>
        					<spring:bind path="command.setuBill.setuIdStr">
            					<input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}">
        					</spring:bind>
	            		</td>
	            		<th width="84px">安装地址：</th>
	            		<td width="273px">
	            			<spring:bind path="command.setuBill.addr">
	                		<input type="text" class="tbInfo2 TextBox" maxlength="50" onKeyUp="goNextInput('costStr');" id="${status.expression}" name="${status.expression}" value="${status.value}" />
	                		<script language="javascript">
								setFormErrorMsg('<c:out value="${status.errorMessage}" />',8,'setuBill.addr');
							</script>
	            			</spring:bind>
	            		</td>
	            		<th width="84px">工程金额：</th>
            			<spring:bind path="command.costStr">
                		<td width="179px">
                			<input type="text" class="tbInfo3 TextBox" maxlength="10" id="${status.expression}" name="${status.expression}" value="${status.value}">
        					<script language="javascript">
				          		setFormErrorMsg('<c:out value="${status.errorMessage}" />',9,'costStr');
				          	</script>
                		</td>
            			</spring:bind>
	        		</tr>
	        		<tr>
	            		<th>安装负责人：</th>
            			<td>
            				<spring:bind path="command.setuBill.mngName">
                			<input type="text" class="tbInfo1 TextBox readonly" readOnly="true" id="${status.expression}" name="${status.expression}" value="${status.value}" />
                			<img src="/images/make-a.gif" class="imgIconButton" onClick="selectStaffer('setuBill.mngId','setuBill.mngName');" />
                			<img src="/images/icon_del.gif" class="imgIconButton" onClick="doClear('setuBill.mngId','setuBill.mngName');" />
            				<script language="javascript">
								setFormErrorMsg('<c:out value="${status.errorMessage}" />',10);
							</script>
            				</spring:bind>
            				<spring:bind path="command.setuBill.mngId">
                				<input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}">
            				</spring:bind>
            			</td>
            			<th>计划完工：</th>
            			<spring:bind path="command.planDateStr">
    					<td>
    						<input type="text" class="tbBillDate TextBox" maxlength="15" onKeyUp="goNextInput('setuBill.remaCostStr');" id="${status.expression}" name="${status.expression}" value="${status.value}" />
    						<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('planDateStr'),'yyyy-mm-dd',this);">
							<select id="planDateHourSelect" class="ddlDateHour" onChange="changeTimeSelect(this,'planDateHour');">
                				<c:forEach var="item" begin="0" step="1" end="23" varStatus="i"><c:if test="${i.index<10}"><c:set var="item" value="0${item}" /></c:if><option value="${item}" <c:if test="${item==command.planDateHour}">selected</c:if>>${item}</option></c:forEach>
							</select>
							<select id="planDateMinuteSelect" class="ddlDateMinute" onChange="changeTimeSelect(this,'planDateMinute');">
                				<c:forEach var="item" begin="0" step="1" end="59" varStatus="i"><c:if test="${i.index<10}"><c:set var="item" value="0${item}" /></c:if><option value="${item}" <c:if test="${item==command.planDateMinute}">selected</c:if>>${item}</option></c:forEach>
							</select>
							<script language="javascript">
						    	setFormErrorMsg('<c:out value="${status.errorMessage}" />',11,'planDateStr');
						    </script>
    					</td>
    					</spring:bind>
            			<th>余额：</th>
            			<spring:bind path="command.remaCostStr">
                		<td>
                			<input type="text" class="tbInfo3 TextBox" maxlength="10" id="${status.expression}" name="${status.expression}" value="${status.value}">
        					<script language="javascript">
				          		setFormErrorMsg('<c:out value="${status.errorMessage}" />',12,'remaCostStr');
				          	</script>
                		</td>
            			</spring:bind>
        			</tr>
        			<tr>
            			<th>安装配备：</th>
            			<td colspan="5">
            				<input type="checkbox" name="need_car" id="need_car" value="1" onclick="checkCbChange(this,'setuBill.needCar');" <c:if test="${command.setuBill.needCar=='Y'}">checked</c:if>>需要派车
            				<input type="checkbox" name="need_high" id="need_high" value="1" onclick="checkCbChange(this,'setuBill.needHigh');" <c:if test="${command.setuBill.needHigh=='Y'}">checked</c:if>>高空作业
            				<input type="checkbox" name="need_weld" id="need_weld" value="1" onclick="checkCbChange(this,'setuBill.needWeld');" <c:if test="${command.setuBill.needWeld=='Y'}">checked</c:if>>焊接作业
            				<input type="checkbox" name="need_stee" id="need_stee" value="1" onclick="checkCbChange(this,'setuBill.needStee');" <c:if test="${command.setuBill.needStee=='Y'}">checked</c:if>>不锈钢
            				<spring:bind path="command.setuBill.needCar"><input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"></spring:bind>
            				<spring:bind path="command.setuBill.needHigh"><input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"></spring:bind>
            				<spring:bind path="command.setuBill.needWeld"><input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"></spring:bind>
            				<spring:bind path="command.setuBill.needStee"><input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"></spring:bind>
            			</td>
        			</tr>
        			<tr>
        				<th>图样：</th>
        				<td colspan="5">
							<div style="position:relative; width:480px; height:28px; overflow:hidden; float:left;">
        						<input type="text" class="TextBox readonly" readonly="readonly" style="width:470px;" name="tmp_att" id="tmp_att">
        					</div>
        					<div style="position:relative;width:40px;height:28px;overflow:hidden;float:left;"> 
								<div style="position:absolute;top:0px;left:0px;width:100%;height:100%;">
									<img class="make-a" src="/images/make-a.gif">
								</div> 
								<input type="file" name="exam_img" id="exam_img" onchange="document.getElementById('tmp_att').value=this.value" style="position:absolute;top:0px;right:0px;cursor:pointer;opacity:0;filter:alpha(opacity:0);z-index:99;"> 
							</div>
							<c:if test="${command.setuBill.examImg!=null && command.setuBill.examImg!=''}">
								<div><a href="${command.setuBill.examImg}" target="_blank">${command.examImgName}</a></div>
							</c:if>
        				</td>
        			</tr>
        			<tr>
            			<th>安装要求：</th>
            			<spring:bind path="command.setuBill.requ">
            			<td colspan="5">
            				<input type="text" class="TextBox" style="width:680px" maxlength="50" name="${status.expression}" id="${status.expression}" value="${status.value}">
            				<script language="javascript">
					          	setFormErrorMsg('<c:out value="${status.errorMessage}" />',13,'setuBill.requ');
					        </script>
            			</td>
            			</spring:bind>
        			</tr>
        			<tr>
            			<th>备注：</th>
            			<spring:bind path="command.setuBill.mark">
            			<td colspan="5">
            				<input type="text" class="TextBox" style="width:680px" maxlength="100" name="${status.expression}" id="${status.expression}" value="${status.value}">
            				<script language="javascript">
					          	setFormErrorMsg('<c:out value="${status.errorMessage}" />',13,'setuBill.mark');
					        </script>
            			</td>
            			</spring:bind>
        			</tr>
    			</table>
    		</div>
			<br>
			<div class="BillNotes">
				<span>开单人：${command.setuBill.creaName} <c:if test="${command.setuBill.creaTime!=null}"><fmt:formatDate value="${command.setuBill.creaTime}" pattern="yyyy-MM-dd HH:mm"/></c:if></span>
				<span>审核人：<c:if test="${command.setuBill.examId!=0}">${command.setuBill.examName} <c:if test="${command.setuBill.examTime!=null}"><fmt:formatDate value="${command.setuBill.examTime}" pattern="yyyy-MM-dd HH:mm"/></c:if></c:if></span>
				<span>单据帐套：${command.tsName}</span>
				<spring:bind path="command.setuBill.tsId">
			        <script language="javascript">
			        	setFormErrorMsg('<c:out value="${status.errorMessage}" />',1);
			        </script>
				</spring:bind>
			</div>
			
		</div>

		<!-- 业务单 底栏按钮 -->
		<div class="Footer">
			<div id="buttonDiv">
				<c:if test="${id!=null && id!=''}">
					<input type="button" class="buttom-a" value=" 打 印 " onClick="doPrint(${id});" <c:if test="${command.setuBill.enab=='N'}">disabled='true'</c:if>>
				</c:if>
				<input type="button" class="buttom-a" value=" 保 存 " onClick="doSave();" ${disabledStr}>
				<input type="button" class="buttom-a" value=" 取 消 " onClick="doCancel();" id="cancelButton">
				<input type="hidden" id="examine" name="examine" value="0">
				<spring:bind path="command.billDateHour"><input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"></spring:bind>
				<spring:bind path="command.billDateMinute"><input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"></spring:bind>
				<spring:bind path="command.planDateHour"><input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"></spring:bind>
				<spring:bind path="command.planDateMinute"><input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"></spring:bind>
				<spring:bind path="command.sychronizeValue"><input type="hidden" name="${status.expression}" value="${status.value}"></spring:bind>
			</div>
			<div id="waitDiv" style="display:none">
    			<span>请稍候...</span>
			</div>
		</div>
		
	</div>
	</form>
</div>
</body>
</html>

